package com.lfx.concurrent;

import java.util.Random;
import java.util.concurrent.CyclicBarrier;

/**
 * @author 李逢喜
 * create 2021/8/2
 */
public class MyThread3 extends Thread{

    private final CyclicBarrier cyclicBarrier;


    private Random random=new Random();

    public MyThread3(CyclicBarrier cyclicBarrier,String name) {
        super(name);
        this.cyclicBarrier = cyclicBarrier;
    }


    @Override
    public void run() {
        try {
            Thread.sleep(random.nextInt(2000));
            System.out.println(super.getName()+"到达公司，开始笔试");

            cyclicBarrier.await();

            Thread.sleep(random.nextInt(2000));
            System.out.println(super.getName()+"笔试结束");

            cyclicBarrier.await();


            Thread.sleep(random.nextInt(2000));
            System.out.println(super.getName()+"面试结束");
            cyclicBarrier.await();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
